<template>
  <div class="app">
    <el-row>
      <el-col :span="12">
        商品添加
      </el-col>
      <el-col :span="12" class="t-r">
        <el-button @click="goBack">返回</el-button>
      </el-col>
    </el-row>

    <el-form ref="form" :rules="rules" :model="form" label-width="80px" class="app-form">
      <el-form-item label="商品名称" prop="goods_name">
        <el-input v-model="form.goods_name" />
      </el-form-item>
      <el-form-item label="商品分类" prop="goods_cat">
        <el-input v-model="form.goods_cat" />
      </el-form-item>
      <el-form-item label="商品价格" prop="goods_price">
        <el-input v-model="form.goods_price" />
      </el-form-item>
      <el-form-item label="商品数量" prop="goods_number">
        <el-input v-model="form.goods_name" />
      </el-form-item>
      <el-form-item label="商品重量" prop="goods_weight">
        <el-input v-model="form.goods_weight" />
      </el-form-item>
      <el-form-item label="商品介绍" prop="goods_introduce">
        <el-input v-model="form.goods_introduce" />
      </el-form-item>
      <el-form-item label="商品图片" prop="pics">
        <el-input v-model="form.pics" />
      </el-form-item>
      <el-form-item label="商品参数" prop="attrs">
        <el-input v-model="form.attrs" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit(form)">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

const rules = {
  goods_name: [
    { required: true, message: '请输入商品名称', trigger: 'blur' }
  ],
  goods_cat: [
    { required: true, message: '请选择商品分类', trigger: 'change' }
  ],
  goods_price: [
    { required: true, message: '请输入商品价格', trigger: 'blur' }
  ],
  goods_number: [
    { required: true, message: '请输入商品数量', trigger: 'blur' }
  ],
  goods_weight: [
    { required: true, message: '请输入商品重量', trigger: 'blur' }
  ]
}

export default {
  name: 'GOODFORM',
  data() {
    return {
      form: {
        goods_name: '',
        goods_cat: '',
        goods_price: '',
        goods_number: '',
        goods_weight: '',
        goods_introduce: '',
        pics: [],
        attrs: []
      },
      rules
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1)
    },
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.app {
  .app-form {

    margin: 50px auto 0 auto;
    width: 60%;
  }
}
</style>
